<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui/plugins/datagrid-detailview.js"></script>
<script type="text/javascript">
 $(function(){
	 $('#district').datagrid({
		 view: detailview,
		 detailFormatter:function(index,row){
		 return '<div style="padding:2px"><table class="ddv"></table></div>';
		 },
		 onExpandRow: function(index,row){
		 var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
		 ddv.datagrid({
			 url:'${pageContext.request.contextPath}/block/getBlocksJson.html?districtId='+row.bha_id,
		 	fitColumns:true,
		 	singleSelect:true,
		 	loadMsg:'正在加载...',
		 	height:'auto',
		 	columns:[[
				 {field:'blockName',title:'板块名称',width:100}
			 ]],
			 onResize:function(){
				   $('#district').datagrid('fixDetailRowHeight',index);
				  },
			  onLoadSuccess:function(){
				  setTimeout(function(){
				  $('#district').datagrid('fixDetailRowHeight',index);
				  },0);
				  }
			 });
		   }
		 });
	 
	 $('#newDistrict').bind('click',function(){
		 $('#dlgdistrict').dialog('open').dialog('setTitle','新建区域');
		 $('#fmdistrict').form('clear');
	 });
	 
	 $('#newblock').bind('click',function(){
		 var row = $('#district').datagrid('getSelected');
		 if (row) {
			 $('#dlgblock').dialog('open').dialog('setTitle','新建版块');
			 $('#blockName').val();
			 $('#bhaid').val(row.bha_id);
		 }
	 });
	 
	 $('#saveDistrict').bind('click',function(){ 
		 $('#fmdistrict').form('submit',{
			 onSubmit: function(){
				 return $(this).form('validate');
			 },
			 success: function(result){
				 var result = eval('('+result+')');
				 if (result.errorMsg){
					 $.messager.show({
					 title: 'Error',
					 msg: result.errorMsg
					 });
				 } else {
					 
					 $('#dlgdistrict').dialog('close'); // close the dialog
					 $('#district').datagrid('reload'); // reload the user data
					 $.messager.show({
						 title: '成功',
						 msg: "数据添加成功"
						 });
				 }
			 	}
			 });
	 });
	 
	 $('#saveblock').bind('click',function(){ 
		 $('#fmblock').form('submit',{
			 onSubmit: function(){
				 return $(this).form('validate');
			 },
			 success: function(result){
				 var result = eval('('+result+')');
				 if (result.errorMsg){
					 $.messager.show({
					 title: 'Error',
					 msg: result.errorMsg
					 });
				 } else {
					 $('#dlgblock').dialog('close'); // close the dialog
					 $('#district').datagrid('reload'); // reload the user data
				 }
			 	}
			 });
	 });
	 
 })
 </script>
  
    <table id="district" class="easyui-datagrid" style="width:auto;height:600px"
		url="${pageContext.request.contextPath}/district/viewDistrictsJson.html"
		singleSelect="true"
		pagination="true"
		pagePosition="both"
		fitColumns="true"
		toolbar="#districtButton"
		>
    <thead>
	    <tr>
	    <th data-options="field:'bhaName',width:100">行政区名字</th>
	    </tr>
    </thead>
   </table>
     <div id="districtButton">
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="newDistrict">新建区域</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="newblock">新建板块</a>
	</div>
	
	<div id="dlgdistrict" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
		closed="true" buttons="#dlg-buttondistrict">
		 <div class="ftitle">区域基本信息</div>
		<form id="fmdistrict" method="post" novalidate action="${pageContext.request.contextPath}/district/addDistrict.html">
			<div class="fitem">
				<label>区域名称:</label>
				<input name="bha_name" id="bha_name" class="easyui-validatebox"  data-options="required:true,validType:'length[3,10]'">
			</div>
		</form>
	</div>	
	<div id="dlgblock" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
		closed="true" buttons="#dlg-buttonblock">
		 <div class="ftitle">版块基本信息</div>
		<form id="fmblock" method="post" novalidate action="${pageContext.request.contextPath}/block/addBlock.html">
			<input name="bhaid" id="bhaid" type="hidden"/>
			<div class="fitem">
				<label>版块名称:</label>
				<input name="blockName" id="blockName" class="easyui-validatebox"  data-options="required:true,validType:'length[3,10]'">
			</div>
		</form>
	</div>		
 <div id="dlg-buttondistrict">
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" id="saveDistrict">保存</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgdistrict').dialog('close')">取消</a>
</div>	
 <div id="dlg-buttonblock">
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" id="saveblock">保存</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgblock').dialog('close')">取消</a>
</div>	